<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <?php include "common/session.php" ?>
    <?php include "common/common.php"; ?>
</head>

<body>
    <div id="wrapper">
	    
	    <?php include "common/header.php" ?>
	    <?php include "common/menu.php"; ?>
	
	    <div id="content">
		    <form action="common/host/host_reservation.php" method="post" class="jqtransform" >
                <div id="calendar">
                    <div style="float: left; padding-right: 5px; line-height: 18px;">From:</div> 
                    <?php
                        require_once('common/calendar/classes/tc_calendar.php');
                        date_default_timezone_set('Asia/Singapore');
		                $thisweek = date('W');
						$thisyear = date('Y');
						$dayTimes = getDaysInWeek($thisweek, $thisyear);

						$date1 = date('Y-m-d', $dayTimes[0]);
						$date2 = date('Y-m-d', $dayTimes[(sizeof($dayTimes)-1)]);

						function getDaysInWeek ($weekNumber, $year, $dayStart = 1) {
						  // Count from '0104' because January 4th is always in week 1
						  // (according to ISO 8601).
						    $time = strtotime($year . '0104 +' . ($weekNumber - 1).' weeks');
						    // Get the time of the first day of the week
						    $dayTime = strtotime('-' . (date('w', $time) - $dayStart) . ' days', $time);
						    // Get the times of days 0 -> 6
						    $dayTimes = array ();
						    for ($i = 0; $i < 7; ++$i) {
							    $dayTimes[] = strtotime('+' . $i . ' days', $dayTime);
						    }
						    // Return timestamps for mon-sun.
						    return $dayTimes;
						}

					    $fromCalendar = new tc_calendar("fromDate", true, false);
					    $fromCalendar->setIcon("common/calendar/images/iconCalendar.gif");
					    $fromCalendar->setDate(date('d', strtotime($date1)), date('m', strtotime($date1)), date('Y', strtotime($date1)));
					    $fromCalendar->setPath("common/calendar/");
					    $fromCalendar->setYearInterval(2012, 2020);
					    //$myCalendar->dateAllow('2009-02-20', "", false);
					    $fromCalendar->setAlignment('left', 'bottom');
					    $fromCalendar->setDatePair('fromDate', 'toDate', $date2);
					    //$myCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
					    $fromCalendar->writeScript();
					?>
					<div style="float: left; padding-left: 10px; padding-right: 5px; line-height: 18px;">To:</div>
					    
					<?php
					    $toCalendar = new tc_calendar("toDate", true, false);
					    $toCalendar->setIcon("common/calendar/images/iconCalendar.gif");
					    $toCalendar->setDate(date('d', strtotime($date1)), date('m', strtotime($date1)), date('Y', strtotime($date1)));
					    $toCalendar->setPath("common/calendar/");
					    $toCalendar->setYearInterval(2012, 2020);
					    //$toCalendar->dateAllow('2009-02-20', "", false);
					    $toCalendar->setAlignment('left', 'bottom');
					    $toCalendar->setDatePair('fromDate', 'toDate', $date2);
					    //$toCalendar->setSpecificDate(array("2011-04-01", "2011-04-04", "2011-12-25"), 0, 'year');
					    $toCalendar->writeScript();
					  ?>

                </div>
                <br />
                <br />
                <table class="sortable" id="dataintable">
                    <tr>
                        <th width=\"4%\">
                        <th>IP</th>
			            <th style='display:none'>Name</th>
			            <th style='display:none'>Location</th>
			            <th>OS</th>
			            <th>CPU</th>
			            <th>Memory</th>
			            <th>HDD</th>
			            <th>NA Build</th>
			            <th>SART Build</th>
			            <th>From:To</th>
			            <th>Status</th>	
		            </tr>	
	
<?php include "common/db/db_connect.php"; ?>

<?php	
	$qry = "select host_ip, host_name, location, os, cpu, memory, harddisk, user_name, " .
			"na_build_id, sart_build_id, startdate, enddate, status from host_view";
	if (isset($_GET["user"])) {
	    $qry = $qry . " where user_name='{$_GET['user']}'";
	}
	$ds  = mysql_query($qry, $con);
	while ($data = mysql_fetch_array($ds)) {
		$host_ip = $data['host_ip'];
		$host_name = $data['host_name'];
		$host_location = $data['location'];
		$host_os = $data['os'];
		$host_cpu = $data['cpu'];
		$host_memory = $data['memory'];
		$host_hdd = $data['harddisk'];
		$user_name = $data['user_name'];
		$na_build = $data['na_build_id'];
		$sart_build = $data['sart_build_id'];
		$start_date = $data['startdate'];
		$end_date = $data['enddate'];
		$host_status = $data['status'];
		
		$checkbox = "<input type=\"checkbox\" name=\"HostSelection[]\" value=\"{$host_ip}\" style=\"float:left\" />";
		if ($user_name != "UNKNOWN") {
		    $checkbox = "<input type=\"checkbox\" name=\"HostSelection[]\" value=\"{$host_ip}\" style=\"float:left\" disabled=\"disabled\" />";
		}
						
		echo "<tr>
		        <td>{$checkbox}</td>
				<td>{$host_ip}</td>
				<td style='display:none'>{$host_name}</td>
				<td style='display:none'>{$host_location}</td>
				<td>{$host_os}</td>
				<td>{$host_cpu}</td>
				<td>{$host_memory}</td>
				<td>{$host_hdd}</td>
				<td>{$na_build}</td>
				<td>{$sart_build}</td>
				<td>{$start_date}:{$end_date}</td>
				<td><img src=\"{$HOST_STATUS[$host_status]['IMAGE']}\" title=\"{$HOST_STATUS[$host_status]['TITLE']}\" /></td>
			  </tr>\n";
		}
?>
    </table>
    <br />
    <input type="submit" name="reserve" value="Reserve" />
</form>
				
<?php include "common/db/db_close.php"; ?>
	    </div>
	
	    <?php include "common/footer.php"; ?>
	
    </div>

</body>

</html>